package com.souche.employment.controller;

import com.souche.employment.CommonUtils;
import com.souche.employment.domain.TagDO;
import com.souche.employment.interceptor.AuthHolder;
import com.souche.employment.mapper.TagMapper;
import com.souche.employment.response.DataResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 
 * BaseController.java created at 2017年8月8日 下午1:11:20
 * @author Ray [email:rayinhangzhou@hotmail.com]
 * Revision History
 * Date            Programmer                   Notes
 * ----------------------------------------------------------
 **/

@RestController
@RequestMapping(value = "/tag")
@Api(value = "/tag", description = "标签接口")
public class TagController {
	@Autowired
	private TagMapper tagMapper;


	@RequestMapping(value="/getNamesByType", method=RequestMethod.GET)
	@ApiOperation(value="获取标签列表")
	public DataResult getNamesByType(@RequestParam String type) {
		List<String> list = tagMapper.getNamesByType(type);
		if (list==null) {
		    list = new ArrayList<>();
        }
		return DataResult.success(list);
	}

	@RequestMapping(value="/addTag", method=RequestMethod.POST)
	@ApiOperation(value="添加标签")
	public DataResult addTag(@RequestParam String type, @RequestParam String name) {
        TagDO tagDO = new TagDO();
		tagDO.setId(CommonUtils.getShortUuid());
		tagDO.setType(type);
		tagDO.setName(name);
		tagDO.setCreater(AuthHolder.mail());
		tagMapper.addTag(tagDO);
		return DataResult.success(null);
	}

	
	
}
